const http = require('http');
const url = require('url');
const app = http.createServer();
app.on('request',(req,res)=>{
    const {query,pathname} = url.parse(req.url,true);
    console.log(query);//get参数数据，形式是a=1&b=2的形式，我们一般称之为urlencoded的形式,加了true之后，自动变成{a:1,b:2}的形式
    console.log(pathname);//url地址
    res.writeHead(200,{'Content-Type':'text/html;charset=utf8'});
    if(pathname == '/index' || pathname == '/'){
        res.end('<h2>欢迎来到首页</h2>');
    }else if(pathname == '/list'){
        res.end('welcome to listpage');
    }else{
        res.end('not found');
    }
})
app.listen(3000);
console.log('网站服务器开启成功');